package com.sumainfor.pc.market.service.gmio;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.market.dao.gmio.GmioTenantPactMapper;
import com.sumainfor.pc.market.feign.EpcFeign.EpcFeign;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 根据房源编号查询在租的租客
 * <p>
 *
 * @author: zc
 * @create: 2019-10-29 14:22
 **/
@Service
public class GmioTenantPactService implements Serializable {

    @Autowired
    GmioTenantPactMapper gmioTenantPactMapper;

    @Autowired
    EpcFeign zpcEpcFeign;


    public List<Map<String,Object>> getTenantPact(String HouId){
        return gmioTenantPactMapper.getTenantPact(HouId);

    }

    /**
     * 根据合同编号获取在租房间的智能门锁
     * @param params
     * @return
     */
    public JsonResult getHouRoom(Map<String,Object> params){
        JsonResult result = new JsonResult();
        Map<String,Object> HouMap = gmioTenantPactMapper.getHouRoom(params);
        JsonResult resultList = zpcEpcFeign.getHouRdRoomList(HouMap);
        Map<String,Object> resultMap = (Map<String, Object>) resultList.get("result");
        List<Map<String,Object>> RoomList = new ArrayList<>();


               List<Map<String,Object>> XunHuanList=  (List<Map<String, Object>>) resultMap.get("list");
        if (MapUtils.getInteger(HouMap,"ProOperaType")==2){//整租
          RoomList = XunHuanList;
          result.put(RoomList);
        }else if(MapUtils.getInteger(HouMap,"ProOperaType")==1){//合租
            String HouConIds = MapUtils.getString(HouMap,"HouConId");
            for (Map<String,Object> map1:XunHuanList){
                if (MapUtils.getString(map1,"HouConId").equals(HouConIds)||MapUtils.getInteger(map1,"HouConType")==1){
                    RoomList.add(map1);
                }
            }
            result.put(RoomList);
        }
        System.out.println("最后的参数"+RoomList);
        return result;
    }
}
